package FIT::Util::Autoload;

use FIT::Class;
use UNIVERSAL;

sub import() {
    my $from = caller;
    no strict 'refs';
    *{"$from\::AUTOLOAD"} = sub {
        my ($self, @params) = @_;
        die "Can't use [$self] without an autoload() method"
            unless $self->can('autoload');
        my $name = our $AUTOLOAD;
        return if $name =~ /DESTROY$/;
        $name =~ s/^.*:://;
        $self->autoload($name, @params);
    };
}
